package com.me.study.javaCore.spi;

import java.util.Iterator;
import java.util.ServiceLoader;
import sun.misc.Service;

/**
 * 
 *
 * @author ME
 * @date   2020/3/2
 */
public class TestSPI {

    public static void main(String[] args) {
        System.out.println("============ 方式一: java.util 包，有源码 ============");
        ServiceLoader<SPIService> load = ServiceLoader.load(SPIService.class);
        Iterator<SPIService> iterator = load.iterator();
        while(iterator.hasNext()) {
            SPIService ser = iterator.next();
            ser.execute();
        }

        System.out.println("\n============ 方式二: sun.misc 包，无源码 ============");
        Iterator<SPIService> providers = Service.providers(SPIService.class);
        while (providers.hasNext()) {
            SPIService spiService = providers.next();
            spiService.execute();
        }
    }
}
